package org.lex.game.sudoku.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.lex.game.sudoku.model.solver.Decision;
import org.lex.game.sudoku.model.solver.SolverObserver;

public class SolverObserverList implements SolverObserver, Iterable<SolverObserver> {

	private List<SolverObserver> observers = new ArrayList<>();

	public boolean add(SolverObserver e) {
		return observers.add(e);
	}

	public Iterator<SolverObserver> iterator() {
		return observers.iterator();
	}

	@Override
	public void beginDecision(Decision decision) {
		for (SolverObserver o : this.observers) {
			o.beginDecision(decision);
		}
	}

	@Override
	public void fillCell(int row, int col, int num) {
		for (SolverObserver o : this.observers) {
			o.fillCell(row, col, num);
		}
	}

	@Override
	public void rollbackDecision(Decision decision, int cellCount) {
		for (SolverObserver o : this.observers) {
			o.rollbackDecision(decision, cellCount);
		}
	}

	@Override
	public void reset() {
		for (SolverObserver o : this.observers) {
			o.reset();
		}
	}
}
